package com.rest.demo.Controller;

import com.rest.demo.repository.DyRcUser;
import com.rest.demo.repository.DyRcUserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/smtDb")//整个路由路径
public class DysmtDB {


//测试数据库是否连接成功
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping(value = "getUser")
    public void getUser(){
        List<Map<String,Object>> list=jdbcTemplate.queryForList("SELECT*FROM dysmt");//dysmt代表数据库表格名称

        for(int i=0;i<list.size();i++){
            String res = (String)list.get(i).get("name");
            int age = (int)list.get(i).get("age");
            System.out.println("age:"+age);
        }


    }



//数据录入
    @Autowired
    private DyRcUserDao DyRcUserDao;

    @ResponseBody
    @RequestMapping(value = "/test",method = RequestMethod.GET)
    public void DysmtDB(){
        DyRcUser user = new DyRcUser();
        user.setName("二哈");
        user.setAge(22);
        DyRcUserDao.add(user);
        System.out.print("可以么？");

    }


    @ResponseBody
    @RequestMapping(value = "/Updata",method = RequestMethod.GET)
    public void DysmtDBUpdata(){
        DyRcUser user = new DyRcUser();
        user.setName("二哈");
        user.setAge(22);
        DyRcUserDao.Updata(user);
        System.out.print("更新？");

    }



}
